<template>
    <div>
  <el-card>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="我的订单" name="first">我的订单</el-tab-pane>
      </el-tabs>
    <el-row>
      <el-button @click="toInvoice()" size="small" type="primary">发票列表</el-button>
    </el-row>
  </el-card>
      <el-card class="box-card" v-if="activeName=='first'">
      <el-row >
        <el-col :span="10" v-for="item in cusItem" >
          <el-card class= "box-card">
            <div slot= "header" class="clearfix">
              <el-button type=" primary" plain disabled size="small">{{item.code}}</el-button>
              <el-button type=" primary"
                         plain disabled size="small">{{item.state | staFit}}</eL-button>
              <el-button  type= "primary" size="small" @click="topay(item)" v-if="item.state==3">付款</el-button>
              <el-button  type= "primary" size="small" @click="toPayLog(item.id)" v-if="item.state==4">支付日志</el-button>
              <el-button  type= "primary" size="small" @click="toReceipt(item.id)" v-if="item.state==4">发票申请</el-button>

            </div>
            <div class="text item" >
              <el-row >
                <el-col :span=18 style="...">
                  下单时间: {{item.createDate|datefmt('YYYY-MM-DD HH:mm:ss')}}
                </el-col>
                <el-col :span=18 style="...">
                  客户名称: {{item. customerName}}
                </el-col>
                <el-col :span=18 style="...">
                  联系人名称: {{item. linkmanName}}
                </el-col>
                <el-col :span=18 styLe="...">
                  联系电话: {{item. linkmanTel}}
                </el-col>
                <el-col :span=18 styLe="..">
                  税前价格: {{item. price}}
                </el-col>
                <el-col :span=18 styLe="...">
                  税率: {{item. taxRate}}%
                </el-col>
                <el-coL :span=18 style="...">
                  税后价格:￥{{item. priceIt}}
                </el-col>
              </el-row>
            </div>
          </el-card>
        </el-col>
      </el-row>



  </el-card>
      <el-card>
      <el-dialog
        title="订单支付"
        :visible.sync="isShowPayMent"
        width="40%">
        <div class="tr_rechbox">
          <div class="tr_rechcho am-form-group">
            <span>支付方式：</span>
            <el-radio v-model="payment.paytype" :label="0"><img src="@/assets/image/zfbpay.png" width="99px" height="33px"></el-radio>
            <el-radio v-model="payment.paytype" :label="1"><img src="@/assets/image/wechatpay.png" width="99px" height="33px"></el-radio>
          </div>
          <div class="tr_rechnum">
            <span>应付金额：</span>
            <p class="rechnum">{{payment.priceit}}元</p>
          </div>
        </div>
        <div class="tr_paybox">
          <el-divider/>
          <span><el-button type="primary" style="float: right;" @click="payMent(payment.paytype)">确认支付</el-button></span>
          <el-divider/>
        </div>
      </el-dialog>
      </el-card>
    </div>

</template>

<script>
    export default {
        name: "CusOrder",
      data(){
          return{
            cusItem:[],
            activeName:'first',
            count: 0,
            isShowPayMent:false,
            payment:{},
            paymodel:{}
          }
      },
      methods:{
        searchList:function (id) {

          this.$http.post("/orders/getCusOrders/"+id).then((res)=>{

            this.cusItem=res.data.result;
          })
        },
        handleClick(tab, event) {
          activeName='second';

        },
        toInvoice:function () {
          this.$router.push("/invoiceList");
        },
        toReceipt:function (orderid) {
          this.$router.push("/receipt?orderid="+orderid);
        },
        //支付日志
        toPayLog:function(id){
          this.$router.push("/payLog?id="+id);
        },
        //支付
        payMent:function (paytype) {
            if(paytype==0){
              //alert(this.paymodel)
              this.$http.post("/payLog/payMoney",this.paymodel).then((res)=>{
                if(res.data.success){
                  document.write(res.data.result);
                }
              })
            }
        },
        topay:function (item) {
          this.isShowPayMent=true;
          this.payment.priceit=item.priceIt;
          this.paymodel=item;
        }
      },
      mounted() {


          var id=0;
        if (sessionStorage.getItem("customer")!=null) {
          id = JSON.parse(sessionStorage.getItem("customer")).id;
        }

          this.searchList(id);



      },
      filters:{
        staFit:function (val) {
          if(val==3){
            return "待付款"
          }
          if(val==4){
            return "已付款"
          }
          if(val==5){
            return "已开发票"
          }
          if(val=6){
            return "订单已关闭"
          }
        }

      }
    }
</script>

<style scoped>

  .rechnum {
    color: #ec5a5b;
    font-size: 24px;
    font-weight: bold;
    display: inline-block;
    line-height: 40px;
  }
  .tr_rechnum {
    height: 40px;
  }
  .tr_rechcho {
    margin-bottom: 20px;
    display: inline-block;
  }
  .am-form-group {
    margin-bottom: 1.5rem;
  }
  .tr_paybox {
    padding: 20px;
  }
  .am-form-group>label>span {
    color: #999;
  }
  .am-radio .am-icon-unchecked, .am-radio .am-icon-checked {
    top: 13px;
  }
</style>
